#!/bin/bash

#set -x
#set -e


function usage() {
    echo "Usage: `basename $0` centerPath  unlabledDatasetFile labeledDatasetFile kStart kInc Kend length dimension"
    exit 1
}


# Paths
Evaluatepath=./

# check for common errors
if [ -z "$1" -o -f "$1" -o $# -ne 8  ]; then
        usage
fi

#extrac the parameter
unlabledDatasetFile="$2"
labeledDatasetFile="$3"
length="$7"
dimension="$8"

# extract working directory
wdir=$(pwd)
centerPath="$1"

# extract centers
kClusters=`seq $4 $5 $6`

# 2. create report-file
date=`date`
datestamp=`date +"%FZ%H-%M"` 
report="${wdir}/report${datestamp}.txt"

echo $report

echo -e "----- evaluation report -----\n\n" >> "$report"
#Evalueate the percision of all file in coreset file
for cluster in $kClusters
do
    echo "The number of cluster is $cluster" >> "$report"
    echo -e "\n" >> "$report"


    #FILES=/disk/sc01/tnguyen8/documents/clusterworkspace/scripts/datasets/centers/*.sh
    listFile=$(ls | grep "_${cluster}_")
    for fname in $listFile
    do
    
    echo "Centers file name: ${fname}" >> "$report"
    "./DetectionEvaluate" $fname $unlabledDatasetFile $labeledDatasetFile $cluster $length $dimension >> "$report"
    # take action on each file. $f store current file name
    done

done
